import random

list1 = []
list2 = [1, 22, 23, 31, 33, 56, 88, 111, 145, 234, 321, 444, 777]
for x in range(10):
    list1.append(random.randint(1, 1000))


def bubble_sort(ls):
    for j in range(len(ls) - 1):
        for i in range(len(ls) - j - 1):
            if ls[i] > ls[i + 1]:
                ls[i], ls[i + 1] = ls[i + 1], ls[i]
        print(ls)


def select_sort(ls):
    for j in range(len(ls) - 1):
        min_index = j
        for i in range(j, len(ls)):
            if ls[i] < ls[min_index]:
                min_index = i
        ls[min_index], ls[j] = ls[j], ls[min_index]
        print(ls)


def insert_sort(ls):
    for i in range(1, len(ls)):
        tmp = ls[i]
        j = i - 1
        while j >= 0 and tmp < ls[j]:
            ls[j + 1] = ls[j]
            j = j - 1
        ls[j + 1] = tmp
        print(ls)


def binary_search(ls, value):
    left = 0
    right = len(ls) - 1
    while left <= right:
        mid = (left + right) // 2
        if ls[mid] > value:
            right = mid - 1
        elif ls[mid] < value:
            left = mid + 1
        else:
            return mid
    return -1


# bubble_sort(list1)
# select_sort(list1)
# insert_sort(list1)
# print(binary_search(list2, 33))

a = '0b110110'
print('2进制数是:', a)
print('2进制转10进制数为:', int(a, 2))
print('2进制转16进制数为:', hex(int(a, 2)))

b = '10023'
print('10进制是:', b)
print('10进制转2进制数是:', bin(int(b)))
print('10进制转16进制数是:', hex(int(b)))

c = '0xabc458'
print('16进制数是', c)
print('16进制转2进制数:', bin(int(c, 16)))
print('16进制转10进制数:', int(c, 16))

d = '0o5174'
print('8进制数是:', d)
print('10进制数是:', int(d, 8))
print('16进制数是:', hex(int(d, 8)))
print('2进制数是:', bin(int(d, 8)))
